package com.cxy.bio;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * 
 * @ClassName: Cilent
 * @Description: TODO(Bio通信的客户端)
 * @author 菜徐鸭
 * @date 2020年5月9日
 *
 */
public class Cilent {
	public static void main(String[] args) throws IOException {
		// 客户端启动必备
		Socket socket = null;
		// 实例化与服务端通信的输入输出流
		ObjectOutputStream outputStream = null;
		ObjectInputStream inputStream = null;
		// 服务器的通信地址
		InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10001);

		try {
			socket = new Socket();
			//连接服务器
			socket.connect(addr);
			outputStream=new ObjectOutputStream(socket.getOutputStream());
			inputStream=new ObjectInputStream(socket.getInputStream());
			
			//向服务器输出请求
			outputStream.writeUTF("YAYA");
			outputStream.flush();
			
			//接收服务器的输出
			System.out.println(inputStream.readUTF());
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if(socket!=null)socket.close();
			if(outputStream!=null)outputStream.close();
			if(inputStream!=null)inputStream.close();
		}

	}
}